package com.ql.boot.dubbo;

import com.alibaba.dubbo.config.*;
import com.alibaba.dubbo.container.Main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * Created by gs on 2017/5/19 0019.
 */
@SpringBootApplication
@EnableAutoConfiguration
public class DubboProviderStarter implements CommandLineRunner {

    private static final Logger logger = LoggerFactory.getLogger(DubboProviderStarter.class);

    public static void main(String[] args) {

        // SpringApplication.run(DubboProviderStarter.class, args);
        new SpringApplicationBuilder(DubboProviderStarter.class).run(args);
    }



    @Bean("rest")
    @ConfigurationProperties(prefix = "dubbo.protocol.rest")
    public ProtocolConfig getRestProtocolConfig() {

        return new ProtocolConfig();
    }


    @Bean("dubbo")
    @ConfigurationProperties(prefix = "dubbo.protocol.dubbo")
    public ProtocolConfig protocolConfig() {
        return new ProtocolConfig();
    }

    public void run(String... strings) throws Exception {
        logger.info("[启动DUBBO]:{}", strings);
        Main.main(strings);
    }
}
